package com.app.couponsharelife.ui.popupwindow

import android.app.Activity
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.widget.PopupWindow
import com.app.couponsharelife.R
import com.app.couponsharelife.ui.listener.OnClickListener
import kotlinx.android.synthetic.main.popupwindow_team_layout.view.*

/**
 *Created by xct on 2019/3/21
 *Description:
 */
class TeamPopupWindow(private val context: Context,private val listener: OnClickListener):PopupWindow(context){
    init {
        val view = LayoutInflater.from(context).inflate(R.layout.popupwindow_team_layout, null)
        view.teamPopup_tvAll.setOnClickListener { listener.click(0,"") }
        view.teamPopup_tvVip.setOnClickListener { listener.click(1,"") }
        view.teamPopup_tvSvip.setOnClickListener { listener.click(2,"") }
        this.contentView = view
        this.isFocusable = true
        setBackgroundAlpha(1f)
        this.setBackgroundDrawable(ColorDrawable(context.resources.getColor(R.color.white)))
        this.isOutsideTouchable = true
        this.update()
        this.animationStyle = R.style.xialapopwindow_anim_style

    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     * 屏幕透明度0.0-1.0 1表示完全不透明
     */
    fun setBackgroundAlpha(bgAlpha: Float) {
        val lp =(context as Activity).window
                .attributes
        lp.alpha = bgAlpha
        context.window.attributes = lp
    }
}